package com.liao.springclouduser.controller.config.dataSourceConfig;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @autuor sufei
 * @date 2018/11/21 15:30
 */
@Configuration
public class DataSorceConfig {

    @Bean(name = "writeDataSource")
    @Qualifier("writeDataSource")
    @ConfigurationProperties(prefix="spring.datasource.write")
    public DataSource writeDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "readDataSource")
    @Qualifier("readDataSource")
    @Primary
    @ConfigurationProperties(prefix="spring.datasource.read")
    public DataSource readDataSource() {
        return DataSourceBuilder.create().build();
    }


}
